﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using Lswweb.Common;

namespace Lswweb.Controls
{
    public static class WebControlExtensions
    {
        #region TextBox

        public static T GetValue<T>(this TextBox col)
        {
            if (col == null)
                return default(T);

            string tbxValue = col.Text.Trim();

            return tbxValue.As<T>();
        }

        public static void SetValue(this TextBox col,IConvertible value)
        {
            if (col == null)
                return;

            col.Text = value.As<string>();
        }

        #endregion

        #region Control

        public static T FindControl<T>(this Control col, string id)
            where T : Control
        {
            return (T)col.FindControl(id);
        }

        #endregion
    }
}
